});
</script>
<?php if(isset($includeBaiduMap) && $includeBaiduMap){ ?>
<script charset="utf-8" src="http://map.qq.com/api/js?v=2.exp&libraries=geometry"></script>
<?php } ?>
<?php if(isset($includeTree) && $includeTree){ ?>
<script type="text/javascript" src="<?php echo SITE_BASE_URL ?>ys-pub/ys-treegrid.js"></script>
<?php } ?>
<?php if(isset($includeDateTime) && $includeDateTime){ ?>
<script type="text/javascript" src="<?php echo SITE_BASE_URL ?>ys-pub/datetimefield.js"></script>
<?php } ?>
<?php if(isset($includeGoogleMap) && $includeGoogleMap){ ?>
<script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="<?php echo SITE_BASE_URL ?>ys-pub/GMap.js"></script>
<?php } ?>
<?php if(isset($includeExcel) && $includeExcel){ ?>
<script type="text/javascript" src="<?php echo SITE_BASE_URL ?>ys-pub/excel/xlsx.core.min.js"></script>
<script type="text/javascript" src="<?php echo SITE_BASE_URL ?>ys-pub/excel/Blob.js"></script>
<script type="text/javascript" src="<?php echo SITE_BASE_URL ?>ys-pub/excel/FileSaver.js"></script>
<script type="text/javascript">
function exportExcel(grid,header,sheetName,fileName) {
    if(!window.btoa) {
        alert('请使用高级浏览器下载，比如chrome,firefox或者非IE兼容版!');
        return;
    }
    var params = grid.store.baseParams;
    params['start'] = 0;
    params['limit'] = 1000;
    var datas = [];
    function getData() {
        ZM.ajax({
            url: grid.url,
            params: params,
            mask:grid,
            success: function(res) {
                datas = datas.concat(res.items);
                if(datas.length < res.totalCount) {
                    params['start'] = datas.length;
                    getData();
                } else {
                    saveXlsxData(header,datas,sheetName,fileName);
                }
            }
        })
    }
    getData();

    function s2ab(s) {
    	var buf = new ArrayBuffer(s.length);
    	var view = new Uint8Array(buf);
    	for (var i=0; i!=s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
    	return buf;
    }

    function saveXlsxData(headers, data, sheetName, fileName) {
        var sheetName = sheetName || 'mySheet';
        var fileName = fileName || 'output.xlsx';
        var output = {},headerKeys = [];
        headers.forEach(function(d,i) {
            var pos = String.fromCharCode(65+i) + 1;
            output[pos] = {'v':d[1]};
            headerKeys.push(d[0]);
        });
        data.forEach(function(d,i) {
            for(var k in d) {
                if(d[k] == null)
                    d[k] =  '';
                var pos = headerKeys.indexOf(k);
                if(~pos) {
                    if(typeof headers[pos][2] == 'function') {
                        d[k] = headers[pos][2](d[k],d);
                    }
                    pos = String.fromCharCode(65+pos) + (i+2);
                    output[pos] = {'v':d[k],'t':'s'};
                }
            }
        });

        output['!ref'] = 'A1:'+String.fromCharCode(65+headers.length)+(data.length+1);
        var Sheets = {};
        Sheets[sheetName] = output;
        var wb = {
            SheetNames: [sheetName],
            Sheets:Sheets
        };

        // XLSX.writeFile(wb, fileName);
        var wbout = XLSX.write(wb, {bookType:'xlsx', bookSST:true, type: 'binary'});
        saveAs(new Blob([s2ab(wbout)],{type:"application/octet-stream"}), fileName)
    }
}
</script>
<?php } ?>
</head>
<body></body>
</html>
